/*
Copyright (C) 2009-2010 Xanadu Development Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "../PacketCreator.h"
#include "../../server/Summon.h"
#include "../../server/ObjectMoving.h"
#include "../Tools.h"

PacketWriter* PacketCreator::showSummon(int playerid, Summon* summon, bool animated) {
	pw.writeShort(SPAWN_SPECIAL_MAPOBJECT);
	pw.writeInt(playerid);
	pw.writeInt(summon->getObjectID());
	pw.writeInt(summon->getSkillid());
	pw.write(0x0A);
	pw.write(summon->getSkillLevel());
	pw.writeShort(summon->getPosition().x);
	pw.writeShort(summon->getPosition().y);
	pw.write(0);
	pw.write(0);
	pw.write(0);
	pw.write(summon->getMovType()); // Movement type
	pw.write(!summon->isPuppet(summon->getSkillid())); // Attack or not
	pw.write(!animated);
	return &pw;
}

PacketWriter* PacketCreator::moveSummon(int playerid, int summonid, Position& start, ObjectMoving& moving) {
	pw.writeShort(MOVE_SUMMON);
	pw.writeInt(playerid);
	pw.writeInt(summonid);
	pw.writeShort(start.x);
	pw.writeShort(start.y);
	pw.write(moving.getPacket()->getBytes(), moving.getPacket()->getLength());
	return &pw;
}

PacketWriter* PacketCreator::removeSummon(int playerid, int summonid, bool animated) {
	pw.writeShort(REMOVE_SPECIAL_MAPOBJECT);
	pw.writeInt(playerid);
	pw.writeInt(summonid);
	pw.write(animated ? 4 : 1);
	return &pw;
}

PacketWriter* PacketCreator::damageSummon(int playerid, int summonid, char notsure, int damage, int mobid) {
	pw.writeShort(DAMAGE_SUMMON);
	pw.writeInt(playerid);
	pw.writeInt(summonid);
	pw.write(notsure);
	pw.writeInt(damage);
	pw.writeInt(mobid);
	pw.write(0);
	return &pw;
}
